﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace HousingDistribution
{
    class ServiceLengthCount
    {
        public static ServiceLengthCount Instance()
        {
            return instance;
        }

        public int ServiceLength(PersonInfo person)
        {
            //未退休
            if (person.retirementTime.Equals(DateProc.InvalidDate()))
            {
                TimeSpan span = DateTime.Now.Subtract(WorkTime(person));
                return span.Days / 365;
            }
            else
            {
                TimeSpan span = person.retirementTime.Subtract(WorkTime(person));
                return span.Days / 365;
            }
        }

        public int ServiceLength(PersonInfo person, DateTime date)
        {
            //未退休
            if (person.retirementTime.Equals(DateProc.InvalidDate()))
            {
                TimeSpan span = date.Subtract(WorkTime(person));
                return span.Days / 365;
            }
            else
            {
                TimeSpan span = person.retirementTime.Subtract(WorkTime(person));
                return span.Days / 365;
            }
        }

        //工作时间的处理：比较工作时间，上学时间， 取较早时间为工作时间
        DateTime WorkTime(PersonInfo person)
        {
            return this.dateProc.GetEarlierDate(person.workTime, person.schoolTime);
        }

        ServiceLengthCount()
        {
        }

        static ServiceLengthCount instance = new ServiceLengthCount();

        DateProc dateProc = new DateProc();
    }
}
